--PLACE HOLDER DO NOT TOUCH

-- function gadget:GetInfo()
	-- return {
	-- name = "Defense",
	-- desc = "Spawns zombie commanders come to kill you.",
	-- author = "Strategist",
	-- date = "7 September 2009",
	-- license = "GNU GPL, v2 or later",
	-- layer = 99,
	-- enabled = true
	-- }
-- end

-- if (gadgetHandler:IsSyncedCode()) then
------------------------------------
-- local createUnit			= Spring.CreateUnit
-- local GetUnitNearestEnemy 	= Spring.GetUnitNearestEnemy
-- local GetUnitIsDead        	= Spring.GetUnitIsDead
-- local getTeam 				= Spring.GetUnitTeam
-- local getQueue 				= Spring.GetCommandQueue
-- local isAllied			    = Spring.AreTeamsAllied
-- local getUnitPos 			= Spring.GetUnitPosition
-- local getDefID 				= Spring.GetUnitDefID


-- local mRandom   = math.random

-- local nextFrame = Spring.GetGameFrame() + 5
-- local thisFrame = 0
-- local level		= 1
-- local count		= 0
-- local timer 	= 0
-- local wave 		= 0
-- local chickenTeamID = nil
-- local grace 	= 60
-- local waveMessage = {}
-- local com 	= {}
-- local coms 	= {}

-- coms[1] = "snipe"
-- coms[2] = "gun"
-- coms[3] = "shotgun"
-- coms[4]	= "lightning"
-- coms[5]	= "rocket"
-- coms[6] = "plane"

-- com["armcom"]			= true
-- com["corcom"]			= true
-- com["tllcom"] 			= true
-- com["raccom"]			= true
-- com["talcom"]			= true
-- com["magcom"] 			= true
-- com["evycom"]	 		= true
-- com["uefcom"] 			= true
-- com["rhycom"] 			= true
-- com["argcom"]			= true
-- com["lord"] 			= true
-- com["xclcom"]			= true
-- com["eichhoernchen"]	= true

	-- function gadget:GameFrame(thisFrame)
	-- if(thisFrame < nextFrame ) then return end
	-- nextFrame = thisFrame + 5
	---------------------------------
		-- if(chickenTeamID == nil) then -- Find the AI
		-- local teams = Spring.GetTeamList()
			-- for _, teamID in ipairs(teams) do		
			-- local teamLuaAI = Spring.GetTeamLuaAI(teamID)
				-- if (teamLuaAI and teamLuaAI ~= "") then
				-- chickenTeamID = teamID
				-- else
				-- Spring.Echo("YOU FORGOT THE AI")
				-- end
			-- end	
		-- end
		-- if(chickenTeamID ~= nil) then 
			-- for ignore,unitID in ipairs(Spring.GetTeamUnits(chickenTeamID)) do
			-- local unitDefID = Spring.GetUnitDefID(unitID)
			-- local unitDef   = UnitDefs[unitDefID or -1]		
				-- if(com[unitDef.name] ~= nil) then
				-- local x, y, z = Spring.GetUnitPosition(unitID)
				-- local nu = Spring.CreateUnit("armnano",x,y,z,1,Spring.GetUnitTeam(unitID)) -- Kill the com and give AI an invincible nano
				-- Spring.SetUnitBlocking(nu,false) 
				-- Spring.DestroyUnit(unitID,false,true,unitID) -- Kill the com and give AI an invincible nano
				-- end
			-- end	
	---------------------------------
			-- if(grace == 0) then	-- Wait for 10 seconds		
				-- if(Spring.GetTeamUnitCount(chickenTeamID) == 1 and count == 0) then	-- If its time to spawn, and there is nothing in que, add something to que
				-- wave = wave + 1
				-- count = count + wave	
				-- local newHP = nil			
					-- for ignore,unitID in ipairs(Spring.GetAllUnits()) do -- Give 30% Boost of current HP every wave
					-- newHP = math.floor(Spring.GetUnitHealth(unitID) * 1.30 - Spring.GetUnitHealth(unitID))
					-- Spring.SetUnitHealth(unitID,Spring.GetUnitHealth(unitID) + newHP)
					-- end	
					-- if(wave == 1) then -- Dont show healed HP on first wave (No damage has been done xD)
					-- local waves = "Lets get started! WAVE: " .. wave 
					-- local healed = nil
					-- local killed = nil
					-- SendToUnsynced("ChickenEvent", waves, healed, killed) -- Send to display widget	
					-- end
					-- if(newHP ~= nil and wave > 1) then -- Show Wave and Healed HP
					-- local waves = taunts() .. "  WAVE: " .. wave 
					-- local healed = "You have been repaired: " .. newHP .. " HPoints" 
					-- local killed = nil
					-- SendToUnsynced("ChickenEvent", waves, healed, killed) -- Send to display widget		
					-- end
				-- end					
				-- if(count > 0) then	-- If there are Coms que'd to be spawned, SPAWN EM							
				-- local unknown = math.random(1,6)
				-- local ranx = mRandom(Game.mapSizeX)
				-- local ranz = mRandom(Game.mapSizeZ)
				-- local nu = createUnit(coms[unknown], ranx, 0, ranz, "n", chickenTeamID)
				-- count = count - 1
				-- Spring.SetUnitBlocking(nu,false)			
				-- end				
		---------------------------------			
				-- for ignore,unitID in ipairs(Spring.GetTeamUnits(chickenTeamID)) do					
				-- local unitDefID = Spring.GetUnitDefID(unitID)
				-- local unitDef   = UnitDefs[unitDefID or -1]
					-- if(unitDef and unitDef.name ~= "armnano") then
					-- local targetID = GetUnitNearestEnemy(unitID)
						-- if(targetID ~= nil) then	
							-- if(timer < 1 or isFree(unitID)) then
							-------------------------------------------------
								-- if(unitDef and unitDef.name == "snipe" and getDist(unitID,targetID) ~= nil and getDist(unitID,targetID) < 1500) then	
								-- local x, y, z = Spring.GetUnitPosition(unitID)
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { 2 }, {})
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE,  { x + mRandom(-1000,1000), y + mRandom(-1000,1000), z + mRandom(-1000,1000)}, { "" })
								-- timer = 6
								-- end
								-- if(unitDef and unitDef.name == "snipe" and getDist(unitID,targetID) ~= nil and getDist(unitID,targetID) > 1499) then
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { 2 }, {})						
								-- Spring.GiveOrderToUnit(unitID, CMD.ATTACK,{targetID}, { "" })
								-- timer = 6
								-- end	
							--------------------------------------------------
								-- if((unitDef and unitDef.name == "shotgun") or (unitDef and unitDef.name == "lightning")) then						
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { 2 }, {})
								-- local x, y, z = Spring.GetUnitPosition(targetID)
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE,  { x + mRandom(-350,350), y + mRandom(-350,350), z + mRandom(-350,350)}, { "" })
								-- timer = 6
								-- end
							--------------------------------------------------	
								-- if(unitDef and unitDef.name == "gun") then						
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { 2 }, {})
								-- local x, y, z = Spring.GetUnitPosition(targetID)
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE,  { x + mRandom(-550,550), y + mRandom(-550,550), z + mRandom(-550,550)}, { "" })
								-- timer = 6
								-- end
							--------------------------------------------------
								-- if(unitDef and unitDef.name == "rocket") then						
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { 2 }, {})
								-- local x, y, z = Spring.GetUnitPosition(targetID)
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE,  { x + mRandom(-750,750), y + mRandom(-750,750), z + mRandom(-750,750)}, { "" })
								-- timer = 6
								-- end		
							--------------------------------------------------
								-- if(unitDef and unitDef.name == "plane") then
								-- Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { 2 }, {})						
								-- Spring.GiveOrderToUnit(unitID, CMD.ATTACK,{targetID}, { "" })
								-- timer = 6
								-- end	
							---------------------------------------------------
							-- timer = 6								
							-- else
							-- timer = timer - 1
							-- end							
						-- else
							-- if(target == nil) then
								-- for ignore,enemyID in ipairs(Spring.GetAllUnits()) do
									-- if(not isAllied(chickenTeamID, getTeam(enemyID))) then
									-- Spring.GiveOrderToUnit(unitID, CMD.ATTACK,{Spring.GetUnitPosition(enemyID)}, { "" })								
									-- end
								-- end							
							-- end	
						-- end	
					-- end	
				-- end								
			-- elseif(grace > 0) then
			-- grace = grace - 1
			-- end	
		-- end	
	-- end	
	-- function gadget:UnitDestroyed(unitID,unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam)
		-- if(chickenTeamID ~= nil and wave > 0) then
		-- local unitDef = UnitDefs[unitDefID or -1]
			-- if(unitTeam == chickenTeamID) then
			-- local waves = nil
			-- local healed = nil
			-- local chickens = Spring.GetTeamUnitCount(chickenTeamID) - 2
				-- if(chickens == 1) then
				-- local killed =  chickens .. " Mini is left"
				-- SendToUnsynced("ChickenEvent", waves, healed, killed)
				-- elseif(chickens > 1) then
				-- local killed =  chickens .. " Mini's are left"
				-- SendToUnsynced("ChickenEvent", waves, healed, killed)
				-- end
			-- else
			-- local player
			-- _, player = Spring.GetTeamInfo(unitTeam)
			-- local name = Spring.GetPlayerInfo(player)
			-- local waves = nil
			-- local healed = nil
			-- local killed =  pwned(name)
			-- SendToUnsynced("ChickenEvent", waves, healed, killed)			
			-- end
		-- end
	-- end	
	-----------------------------------	
	-- function isFree(unitID)
	-- return(getQueue(unitID)[1] == nil)
	-- end
		
	-- function getDist(unitID,targetID)
	-- local posx, posy, posz = Spring.GetUnitPosition(unitID)
	-- local uposx, uposy, uposz = Spring.GetUnitPosition(targetID)
		-- if(posx ~= nil and uposx ~= nil) then
		-- return math.sqrt(math.pow(posx - uposx,2) + math.pow(posz - uposz,2))
		-- else
		-- return nil
		-- end	
	-- end	
	
	-- function pwned(name)
	-- local pwnt = {}
	-- pwnt[1] = name .. " Got PWNED!"
	-- pwnt[2] = name .. " FAILED!"
	-- pwnt[3] = name .. " Noobed it out."
	-- pwnt[4] = name .. " Died."
	-- pwnt[5] = name .. " Needs to grow a pair!"
	-- pwnt[6] = name .. " Was raped."
	-- pwnt[7] = name .. " Sucked hard."
	-- pwnt[8] = name .. " Has no skill."
	-- pwnt[9] = name .. " Needs to go to AIM.COM!"
	-- pwnt[10] = name .. " Wonders why his insides are red."
	-- local unknown = math.random(1,10)
	-- return pwnt[unknown]
	-- end
	
	-- function taunts()
	-- local taunt = {}
	-- taunt[1] = "Not hard enough?"
	-- taunt[2] = "Try this!"
	-- taunt[3] = "Can you win?"
	-- taunt[4] = "No way you can make it."
	-- taunt[5] = "I bet you will FAIL."
	-- taunt[6] = "This will be tougher."
	-- taunt[7] = "This will be harder."
	-- taunt[8] = "Can you make it?"
	-- taunt[9] = "Hehehehe..."
	-- taunt[10] = "You'll be suprised!"
	-- taunt[11] = "Dude you suck..."
	-- taunt[12] = "Confident much?"
	-- taunt[13] = "You are soo WEAK!"
	-- taunt[14] = "Its getting harder..."
	-- taunt[15] = "Your gonna DIE soon!"
	-- taunt[16] = "How long will you live?"
	-- taunt[17] = "Can you survive?"
	-- taunt[18] = "How will you survive?"
	-- taunt[19] = "Lets heat things up."
	-- taunt[20] = "Here's a challenge!"
	-- taunt[21] = "Here they COME!"
	-- taunt[22] = "Too many yet?"
	-- taunt[23] = "You WILL FAIL!"
	-- taunt[24] = "You WILL DIE."
	-- taunt[25] = "You WILL LOSE!"
	-- taunt[26] = "Got any skill?"
	-- taunt[27] = "So you got some skill eh?"
	-- taunt[28] = "How long can you last?"
	-- taunt[29] = "No way you can survive."
	-- taunt[30] = "I ALWAYS win!"
	-- taunt[31] = "MUAHAHAHA..."
	-- taunt[32] = "You can't beat me."
	-- taunt[33] = "No way will you make it."
	-- taunt[34] = "THERES NO END TO EM!!!"
	-- taunt[35] = "Had enough?"
	-- taunt[36] = "Had enough yet?"
	-- taunt[37] = "Hard enough yet?"
	-- taunt[38] = "Tough enough yet?"
	-- taunt[39] = "HAHAHAHA"
	-- taunt[40] = "Want to keep going?"
	-- taunt[41] = "I never lose."
	-- taunt[42] = "I wont lose to you."
	-- taunt[43] = "Your dieing..."
	-- taunt[44] = "BEHOLD MY ONSLAUGHT"
	-- taunt[45] = "Can you survive this hell?"
	-- taunt[46] = "Welcome to HELL."
	-- taunt[47] = "AIM NOOB"
	-- taunt[48] = "WOW YOU FAIL"
	-- taunt[49] = "What a NOOB"
	-- taunt[50] = "Your so worthless"
	-- local unknown = math.random(1,50)
	-- return taunt[unknown]
	-- end
------------------------------------------------------------------------------------	
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
-- else

-- local Script = Script
-- local SYNCED = SYNCED

-- function WrapToLuaUI(_, chickenEventArgs, healed, killed)
  -- if (Script.LuaUI('ChickenEvent')) then
    -- Script.LuaUI.ChickenEvent(chickenEventArgs, healed, killed)
  -- end
-- end

-- function gadget:Initialize()
  -- gadgetHandler:AddSyncAction('ChickenEvent', WrapToLuaUI)
-- end


-- end
	